package com.inno.system.mq;

import cn.hutool.core.util.IdUtil;
import com.inno.system.entity.CreateNewsMessageBO;
import com.inno.system.entity.PlannerNews;
import com.inno.system.service.PlannerNewsService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author sean
 */
@Service
@RocketMQMessageListener(topic = "createNews",consumerGroup = "zey-inno-system")
@Slf4j
public class CreateNewsListener implements RocketMQListener<CreateNewsMessageBO> {
    @Resource
    private PlannerNewsService plannerNewsService;
    @Override
    public void onMessage(CreateNewsMessageBO bo) {
        log.info("创建新闻消息消费者:{}",bo);
        PlannerNews news = new PlannerNews();
        news.setId(IdUtil.getSnowflakeNextId());
        news.setContent(bo.getContent());
        news.setTitle(bo.getTitle());
        news.setCreateTime(new Date());
        plannerNewsService.insert(news);
    }
}
